using System;

namespace KsWare.Breconium.Core
{
	public class CommandException : Exception
	{
		public CommandException(object error):base(GetMessage(error)) {
			NativeError = error;
			if(error is Json) {
				var json = (Json) error;
				Name = json.String("name");
				LineNumber = (int) json.Long("lineNumber", 0);
			} else {
				
			}
		}

		public object NativeError { get; private set; }

		private static string GetMessage(object error) {
			string message = "Unknown Error";
			if(error is Json) {
				var json = (Json) error;
				message=json.String("message");
			} else {
				message = error.ToString();
			}
			return message;
		}

		public string Name { get; private set; }
		public int LineNumber { get; private set; }
	}
}